﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[AddComponentMenu("MyGame/player")]
public class Player : MonoBehaviour
{
    // Start is called before the first frame update
    public float m_speed = 1.0f;
    protected Transform m_transform;
    public Transform m_rocket;
    float m_rocketTimer = 0;
    public float m_life = 3;

    void Start()
    {
        m_transform = this.transform;
    }
    private void OnTriggerEnter(Collider other)
    {
        if (other.tag!="PlayerRocket" && other.name!="Background")
        {
            Debug.Log(other.name);
            m_life -= 1;
            if (m_life <= 0)
            {
                Destroy(this.gameObject);
            }
        }
    }

    // Update is called once per frame
    void Update()
    {
        m_rocketTimer -= Time.deltaTime;
        if (m_rocketTimer <= 0)
        {
            m_rocketTimer = 0.1f;
            if (Input.GetKey(KeyCode.Space) || Input.GetMouseButton(0))
            {
                Instantiate(m_rocket, m_transform.position, m_transform.rotation);
            }
        }

        float movev = 0;
        float moveh = 0;

        if (Input.GetKey(KeyCode.UpArrow))
        {
            movev += m_speed * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.DownArrow))
        {
            movev -= m_speed * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            moveh -= m_speed * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.RightArrow))
        {
            moveh += m_speed * Time.deltaTime;
        }
        this.transform.Translate(new Vector3(moveh, 0, movev));
    }



}
